﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package mochicrypt {
    import flash.events.*;
    import flash.display.*;
    import mochicrypt.as3.*;
    import flash.utils.*;
    import flash.net.*;
    import flash.system.*;

    public dynamic class Preloader extends MovieClip {

        private static const VERSION:String = "3.2c";
        private static const PAYLOAD_NAME:String = "mochicrypt.Payload";
        private static const PATCH_URL:String = Config.getString("patchURL", "http://cdn.mochiads.com/patch.swf");

        private var payloadLoader:Loader;
        private var patchProgress:Number = 0;
        private var payloadProgress:Number = 0;
        private var payloadDoneTime:Number = -1;
        private var lastProgress:Number = 0;
        private var patchTimeoutMsec:Number = 5000;
        private var patchFailed:Boolean = false;
        public var background:Background;
        private var payloadDone:Boolean = false;
        private var patchDone:Boolean = false;
        public var icon:LockIcon;
        private var patchLoader:Loader;

        public function Preloader(){
            this.patchLoader = new Loader();
            super();
            loaderInfo.addEventListener(ProgressEvent.PROGRESS, this.progressHandler);
            loaderInfo.addEventListener(Event.INIT, this.initHandler);
            loaderInfo.addEventListener(Event.COMPLETE, this.completeHandler);
            loaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.ioErrorHandler);
        }
        public function parse_vsn(_arg1:String):Number{
            var _local2:Array = _arg1.split(" ")[1].split(",");
            var _local3:Number = parseInt(_local2[0]);
            if (_local3 < 10){
                return (_local3);
            };
            if (_local3 === 10){
                return ((_local3 + Math.max(0, (parseInt(_local2[1]) - 1))));
            };
            return ((_local3 + 2));
        }
        public function ad_finished():void{
            this.finish();
        }
        public function ad_progress(_arg1:Number):void{
        }
        private function completeHandler(_arg1:Event):void{
            if (this.payloadDone){
                return;
            };
            this.payloadDone = true;
            nextFrame();
        }
        private function finish():void{
            var S:* = null;
            var i:* = 0;
            var j:* = 0;
            var k:* = 0;
            var n:* = 0;
            var u:* = 0;
            var v:* = 0;
            var btn:* = null;
            if (this.payloadLoader){
                return;
            };
            if (((Config.getBool("showLock", true)) && (this.icon))){
                removeChild(this.icon);
            };
            removeChild(this.background);
            var payloadClass:* = Class(getDefinitionByName(PAYLOAD_NAME));
            var data:* = ByteArray(new (payloadClass)());
            if (data.length > 0){
                S = new ByteArray();
                n = (data.length - 32);
                i = 0;
                while (i < 0x0100) {
                    S.writeByte(i);
                    i = (i + 1);
                };
                j = 0;
                i = 0;
                while (i < 0x0100) {
                    j = (((j + S[i]) + data[(n + (i & 31))]) & 0xFF);
                    u = S[i];
                    S[i] = S[j];
                    S[j] = u;
                    i = (i + 1);
                };
                if (n > 131072){
                    n = 131072;
                };
                var _local2:int;
                j = _local2;
                i = _local2;
                k = 0;
                while (k < n) {
                    i = ((i + 1) & 0xFF);
                    u = S[i];
                    j = ((j + u) & 0xFF);
                    v = S[j];
                    S[i] = v;
                    S[j] = u;
                    data[k] = (data[k] ^ S[((u + v) & 0xFF)]);
                    k = (k + 1);
                };
                data.uncompress();
            };
            if (!this.patchFailed){
                try {
                    data = this.patchLoader.content["patch"](data);
                } catch(error:Error) {
                };
            };
            if (data[3] > this.parse_vsn(Capabilities.version)){
                btn = new Button();
                btn.x = ((loaderInfo.width - btn.width) / 2);
                btn.y = ((loaderInfo.height - btn.height) / 2);
                addChild(btn);
            } else {
                if (data.length > 0){
                    this.payloadLoader = new Loader();
                    addChild(this.payloadLoader);
                    this.payloadLoader.loadBytes(data);
                };
            };
            this.patchLoader.unload();
            loaderInfo.removeEventListener(ProgressEvent.PROGRESS, this.progressHandler);
            loaderInfo.removeEventListener(Event.INIT, this.initHandler);
            loaderInfo.removeEventListener(Event.COMPLETE, this.completeHandler);
            loaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, this.ioErrorHandler);
            this.patchLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, this.patchIOErrorHandler);
            this.patchLoader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, this.patchProgressHandler);
            this.patchLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, this.patchCompleteHandler);
            if (this.icon){
                this.icon.removeEventListener(MouseEvent.CLICK, this.lockClicked);
            };
            this.patchLoader = null;
        }
        private function update_progress():void{
            var _local1:Number;
            if (this.payloadDone){
                this.payloadProgress = 1;
                if (this.payloadDoneTime < 0){
                    this.payloadDoneTime = getTimer();
                };
            };
            if (this.patchDone){
                this.patchProgress = 1;
            } else {
                if (this.payloadDone){
                    if (this.patchProgress > this.lastProgress){
                        this.payloadDoneTime = getTimer();
                    } else {
                        if ((getTimer() - this.payloadDoneTime) >= this.patchTimeoutMsec){
                            this.patchDone = true;
                            this.patchFailed = true;
                        };
                    };
                };
            };
            this.lastProgress = Math.max(this.lastProgress, Math.min(this.payloadProgress, this.patchProgress));
        }
        public function ad_failed():void{
        }
        private function initHandler(_arg1:Event):void{
            var event:* = _arg1;
            var options:* = {
                mochicrypt_version:VERSION,
                id:Config.getString("id", "test"),
                res:((("" + loaderInfo.width) + "x") + loaderInfo.height),
                no_bg:!(Config.getBool("adBackground", false)),
                color:Config.getInt("barForeColor", 0xFF8A00),
                background:Config.getInt("barBackColor", 16777161),
                outline:Config.getInt("barOutlineColor", 13994812),
                bar_offset:(Config.getBool("showLock", true)) ? 20 : 0,
                show_lock:Config.getBool("showLock", true),
                no_branding:Config.getBool("noBranding", false),
                clip:this,
                progress_override:this.progress_override,
                ad_started:this.ad_started,
                ad_finished:this.ad_finished,
                ad_loaded:this.ad_loaded,
                ad_failed:this.ad_failed,
                ad_skipped:this.ad_skipped,
                ad_progress:this.ad_progress
            };
            this.patchLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, this.patchIOErrorHandler);
            this.patchLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, this.patchProgressHandler);
            this.patchLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, this.patchCompleteHandler);
            try {
                this.patchLoader.load(new URLRequest(PATCH_URL));
            } catch(error:Error) {
                patchDone = true;
                patchFailed = true;
            };
            this.background = new Background();
            addChild(this.background);
            MochiAd.showPreGameAd(options);
            if (Config.getBool("showLock", true)){
                this.icon = new LockIcon();
                this.icon.addFrameScript(49, this.icon.stop);
                this.icon.x = 10;
                this.icon.y = (loaderInfo.height - 20);
                this.icon.buttonMode = true;
                this.icon.useHandCursor = true;
                this.icon.addEventListener(MouseEvent.CLICK, this.lockClicked);
                addChild(this.icon);
            };
            if (((loaderInfo.bytesTotal) && ((loaderInfo.bytesLoaded == loaderInfo.bytesTotal)))){
                this.completeHandler(event);
            };
        }
        public function progress_override(_arg1:Object):Number{
            this.update_progress();
            return (this.lastProgress);
        }
        public function ad_loaded(_arg1:Number, _arg2:Number):void{
        }
        private function ioErrorHandler(_arg1:IOErrorEvent):void{
        }
        private function patchCompleteHandler(_arg1:Event):void{
            if (this.patchDone){
                return;
            };
            this.patchDone = true;
            this.update_progress();
        }
        public function ad_skipped():void{
        }
        public function ad_started():void{
        }
        private function patchProgressHandler(_arg1:ProgressEvent):void{
            if (_arg1.bytesLoaded == _arg1.bytesTotal){
                this.patchProgress = 1;
                this.patchDone = true;
            } else {
                this.patchProgress = (Number(_arg1.bytesLoaded) / _arg1.bytesTotal);
            };
            this.update_progress();
        }
        private function patchIOErrorHandler(_arg1:IOErrorEvent):void{
            this.patchDone = true;
            this.patchFailed = true;
            this.update_progress();
        }
        private function lockClicked(_arg1:Event):void{
            navigateToURL(new URLRequest((("https://www.mochimedia.com/r/g/" + Config.getString("slug", "example-flash_api-test")) + "?d=l")));
        }
        private function progressHandler(_arg1:ProgressEvent):void{
            if (_arg1.bytesLoaded == _arg1.bytesTotal){
                this.payloadProgress = 0;
            } else {
                this.payloadProgress = (Number(_arg1.bytesLoaded) / _arg1.bytesTotal);
            };
            this.update_progress();
        }

    }
}//package mochicrypt 

import flash.events.*;
import flash.display.*;
import flash.net.*;
import flash.text.*;

class Button extends SimpleButton {

    public function Button(){
        var _local1 = "Download the latest\nAdobe Flash Player";
        upState = new State(0xFFFFFF, _local1);
        downState = new State(0xCCCCCC, _local1);
        hitTestState = upState;
        overState = upState;
        addEventListener(MouseEvent.CLICK, this.buttonClicked);
        width = upState.width;
        height = upState.height;
    }
    public function buttonClicked(_arg1:Event):void{
        navigateToURL(new URLRequest("http://get.adobe.com/flashplayer/"));
    }

}
class State extends Sprite {

    public function State(_arg1:uint, _arg2:String){
        var _local3:TextFormat = new TextFormat("Verdana");
        _local3.align = TextFormatAlign.CENTER;
        var _local4:TextField = new TextField();
        _local4.text = _arg2;
        _local4.multiline = true;
        _local4.x = (_local4.y = 2);
        _local4.setTextFormat(_local3);
        _local4.width = (_local4.textWidth + 4);
        _local4.height = (_local4.textHeight + 4);
        addChild(_local4);
        var _local5:Graphics = graphics;
        _local5.beginFill(_arg1);
        _local5.lineStyle(1, 0);
        _local5.drawRoundRect(0, 0, (_local4.width + 4), (_local4.height + 4), 4);
    }
}
